package listbyorder.access201_300.test202;

import java.util.HashSet;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/18 11:23
 */
public class Solution1 {

    public boolean isHappy(int n) {
        if(n == 1) return true;
        HashSet<Integer> set = new HashSet<>();
        while(n != 1){
            String cur = n + "";
            int temp = 0;
            for(int i = 0; i < cur.length(); i++){
                temp += (cur.charAt(i) - '0') * (cur.charAt(i) - '0');
            }
            if(set.contains(temp)){
                return false;
            }
            set.add(n);
            n = temp;
        }
        return true;
    }
}
